//
//  LHProvinceViewController.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/13.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHProvinceViewController.h"
#import "LHProvinceView.h"
#import "MyNavgationView.h"
#import "LHCityViewController.h"
#import "LHNetworkHandle.h"
#import "LHProvinceModel.h"
#import "MBProgressHUD.h"

@interface LHProvinceViewController ()<jumpToCityDelegate>
@property (nonatomic, retain)LHProvinceView *provinceView;
@property (nonatomic, retain)MyNavgationView *navi;
@property (nonatomic ,retain)NSMutableArray *provinceModelArr;
@end

@implementation LHProvinceViewController

- (void)dealloc
{
    [_provinceView release];
    [_navi release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.provinceModelArr = [NSMutableArray array];
    [self creatNavigation];
    
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:hud];
    hud.dimBackground = YES;
    hud.minShowTime = 2;
    [hud showAnimated:YES whileExecutingBlock:^{
        [self getdata];
    } completionBlock:^{
        [hud removeFromSuperview];
        [hud release];
    }];

}

-  (void)getdata
{
    [LHNetworkHandle getDataWithURL:@"http://119.57.103.173:8080/tsp/regionWSAction!findChildByID.do?regionId=001001" completion:^(id result) {
        
        NSMutableArray *arr = [result objectForKey:@"regions"];
        
        for (NSMutableDictionary *tempdic in arr) {
            LHProvinceModel *proModel = [[LHProvinceModel alloc]initWithDic:tempdic];
            [self.provinceModelArr addObject:proModel];
            [proModel release];
        }
        [self creatProvinceView];
    }];
}

/**
 *  自定义导航
 */
- (void)creatNavigation
{
    self.navi = [[MyNavgationView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    [_navi creatTitle:@"全国景区"];
    [self.view addSubview:_navi];
    [_navi release];
}

/**
 *  创建省视图
 */
- (void)creatProvinceView
{
    self.provinceView = [[LHProvinceView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    [self.view addSubview:_provinceView];
    _provinceView.proModelArr = self.provinceModelArr;
    [_provinceView release];
    _provinceView.delegate = self;
}
/**
 *  跳转协议方法
 *
 *  @param indexPath 点击的item坐标
 */
- (void)jumpToCityWithIndexPath:(NSIndexPath *)indexPath
{
    LHCityViewController *cityVC = [[LHCityViewController alloc]init];
    
    //将获取到的ID传给城市页面 供其根据ID获取数据
    cityVC.myCityID = [self.provinceModelArr[indexPath.item] cityID];
    cityVC.titleName = [self.provinceModelArr[indexPath.item]namec];
    cityVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:cityVC animated:YES];
    [cityVC release];
}

/**
 *  导航栏左侧按钮点击方法
 */
- (void)backToHomePage
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
